package config

import (
	"fmt"
	"os"

	v2 "gopkg.in/yaml.v2"
)

type ServerConfigType struct {
	Server        string   `yaml:"server" json:"server"`
	Redis         string   `yaml:"redis" json:"redis"`
	RedisPassword string   `yaml:"redis-password" json:"redis-password"`
	RedisLuaSha   string   `yaml:"redis-lua-sha" json："redis-lua-sha"`
	Services      []string `yaml:"services" json:"services"`
	Namesrv       string   `yaml:"namesrv" json:"namesrv"`
}

var ServerConfig ServerConfigType

func ServerConfigInit(path string) error {
	data, err := os.ReadFile(path)

	if err != nil {
		fmt.Println(err)
		return err
	}
	if err = v2.Unmarshal(data, &ServerConfig); err != nil {
		fmt.Println(err)
		return err
	}
	return nil
}
